/**
 * Copyright： 版权所有 违者必究 2013
 */
package com.apes.oap.session;

import com.apes.oap.AbstractInterceptor;
import com.apes.oap.Constants;
import com.apes.oap.RopRequestContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 将{@link Session}绑定到{@link RopSessionHolder}中，默认注册。
 *
 */
public class SessionBindInterceptor extends AbstractInterceptor {

	protected final Log logger = LogFactory.getLog(this.getClass());

	public void beforeService(RopRequestContext ropRequestContext) {
		Session session = ropRequestContext.getSession();
		if (session != null) {
			RopSessionHolder.put(session);
		}
	}

	public void beforeResponse(RopRequestContext ropRequestContext) {
		Session session = ropRequestContext.getSession();
		if (session != null && session.isChanged()) {
			session.removeAttribute(Constants.SESSION_CHANGED);
			SessionManager sessionManager = ropRequestContext.getRopContext().getSessionManager();
			sessionManager.addSession(ropRequestContext.getSessionId(), session);
		}
		RopSessionHolder.remove();
	}
}
